package com.fh.pms.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fh.pms.entity.PmsBrand;
import com.fh.pms.service.IPmsBrandService;
import com.fh.result.ResultObject;
import com.fh.search.BrandSearch;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author F
 * @since 2021-05-20
 */
@RestController
@RequestMapping("/pms/brand")
public class PmsBrandController {

    @Autowired
    private IPmsBrandService iPmsBrandService;



    @GetMapping
    public ResultObject queryBrandPage(Page<PmsBrand> page, BrandSearch brandSearch){

        QueryWrapper<PmsBrand>queryWrapper=new QueryWrapper<>();

        if(StringUtils.isNotBlank(brandSearch.getName())){
            queryWrapper.like("name", brandSearch.getName());
        }
        iPmsBrandService.page(page,queryWrapper);
        return  ResultObject.success(page);
    }


    @PostMapping
    public ResultObject saveOrUpdateBrand(@RequestBody PmsBrand pmsBrand){
        iPmsBrandService.saveOrUpdate(pmsBrand);
        return   ResultObject.success();
    }


    @GetMapping("/{Id}")
    public ResultObject getBrandById(@PathVariable("Id") Long roleId){
        PmsBrand pmsBrand= iPmsBrandService.getById(roleId);
        return ResultObject.success(pmsBrand);
    }
    //删除
    @DeleteMapping("/{dId}")
    public ResultObject deleteBrandById(@PathVariable("dId")Long roleId){
        iPmsBrandService.removeById(roleId);
        return ResultObject.success();
    }
    //批量删除
    @DeleteMapping
    public ResultObject deleteBrandBach(@RequestBody List<Long> roleIds){
        iPmsBrandService.removeByIds(roleIds);
        return ResultObject.success();
    }



    @PostMapping("/show")
    public ResultObject updateShowStatus(Long id,Integer status){
        iPmsBrandService.updateShowStatus(id,status);
        return ResultObject.success();
    }

    @PostMapping("/factory")
    public ResultObject updateFactoryStatus(Long id,Integer factoryStatus){
        iPmsBrandService.updateFactoryStatus(id,factoryStatus);
        return ResultObject.success();
    }



   /* ----*/
   @GetMapping("/parent")
   public ResultObject getBrandListAll(){
       return ResultObject.success(iPmsBrandService.list());
   }

}
